<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page isELIgnored="false" %> 

<%String path = request.getContextPath();%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	
    <link href="<%=path %>/css/index.css" type="text/css" rel="stylesheet" />
    <link href="<%=path %>/css/base.css" type="text/css" rel="stylesheet" />
    
    <style type="text/css">
		.c1-bline{border-bottom:#999 1px dashed;border-top:1px;}
		.f-right{float:right}
		.f-left{float:left}
		.clear{clear:both}
	</style>
	

    <script type='text/javascript' src='<%=path %>/dwr/interface/cartService.js'></script>
    <script type='text/javascript' src='<%=path %>/dwr/engine.js'></script>
    <script type='text/javascript' src='<%=path %>/dwr/util.js'></script>
    
    <script language="javascript">
            function modiNum(goodsId,quantity)
	        {
	            var r1= /^[0-9]*[1-9][0-9]*$/　　//正整数 
	            var val=r1.test(quantity); //str为你要判断的字符 执行返回结果 true 或 false
	            if(val==false)
	            {
	                alert("数量必须是数字,请重新输入");
	            }
	            else
	            {
	                document.getElementById("indicator1").style.display="block";
	                cartService.modiNum(goodsId,quantity,callback);
	            }
	        }
	        
	        
	        
	        
	        function delGoodsFromCart(goodsId)
	        {
	            document.getElementById("indicator1").style.display="block";
	            cartService.delGoodsFromCart(goodsId,callback);
	        }
	        
	        function clearCart()
	        {
	            document.getElementById("indicator1").style.display="block";
	            cartService.clearCart(callback);
	        }
	        
	        
	        function callback(data)
	        {
	            
	            if(data=="kucunbuzu")
	            {
	                 alert("库存不足");
	                 document.location.reload(true);
	            }
	            if(data=="yes")
	            {
	                document.getElementById("indicator1").style.display="none";
	                document.location.reload(true);
	            }
	        }
	        
	        function jixu()
	        {
	            var url="<%=path %>/index.action";
	            window.location.href=url;
	        }
	        
	        function orderQueren()
	        {
	            var ss=<s:property value="#session.cart.totalPrice"/>;
	            if(ss==0)
	            {
	                alert("购物车中无商品");
	                return false;
	            }
	            
	            var url="<%=path %>/orderQueren.action";
	            window.location.href=url;
	        }
    </script>
	
	
</head>
  
<body>
	<div class="banner">
        <jsp:include flush="true" page="/qiantai/top.jsp"></jsp:include>
	</div>


    <div class="main01" style="margin-top: 10px;">
    	<!-- <h2>
            <span style="font-size: 18px;font-weight:900 ">购物车</span>
            <div class="right" style="font-size: 14px;">dd</div>
        </h2> -->
        <div class="goods">
        	 <s:set name="items" value="#session.cart.items"/>
	                        <table width="99%" border="0" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" align="center" style="margin-top:8px">
					              <tr align="left" bgcolor="#FAFAF1" >
					                  <td>商品名称</td>
					                  <td>价格</td>
					                  <td>数量</td>
					                  <td>金额</td>
					                  <td>删除</td>
				                  </tr>
								  <s:iterator value="#items">
								  <tr align='left' bgcolor="#FFFFFF" >
									  <td><s:property value="value.goods.goodsName"/></td>
									  <td>￥<s:property value="value.goods.goodsTejia"/><br/></td>
									  <td>
									     <form>
									         <input type="text" name="shuliang" value="<s:property value="value.goodsQuantity"/>" size="4"/>
									         <input type="button" value="更新" onclick="modiNum(<s:property value="value.goods.goodsId"/>,this.form.shuliang.value)"/>
									      </form>
									  </td>
									  <td>￥<s:property value="value.goodsQuantity * value.goods.goodsTejia"/></td>
									  <td><input onClick="delGoodsFromCart(<s:property value="value.goods.goodsId"/>)" type="button" value="删除"/></td>
								  </tr>
								  </s:iterator>
					              <tr style="height: 66px;">
					                 <td colspan="6" >
					                    <img src="<%=path %>/img/me03.gif" style="margin-left: 0px;"/> 
									            总金额：￥<span id="totalMoney"><s:property value="#session.cart.totalPrice"/></span>&nbsp;&nbsp;&nbsp;&nbsp;
									    <img id="indicator1" src="<%=path %>/img/loading.gif" style="display:none"/>
									 </td>
					              </tr>				
	        				</table>
	        				<table>
	        				   <tr height="7"><td></td></tr>
			                   <tr>
			                       <td width="120"></td>
			                       <td><input type="button" value="清空购物车" onclick="clearCart()" style="width: 130px;"/></td>
			                       <td><input type="button" value="继续购物" onclick="jixu()" style="width: 130px;"/></td>
			                       <td><input type="button" value="去收银台" onclick="orderQueren()" style="width: 130px;"/></td>
			                   </tr>
			                   <tr height="7"><td></td></tr>
			               </table> 
        </div>
    </div>
    
    
    <br/>
    <div class="bottom" style="position:absolute;bottom:0px;">
        <jsp:include flush="true" page="/qiantai/down.jsp"></jsp:include>
    </div>
</body>
</html>
